﻿using Microsoft.EntityFrameworkCore;
using Model.CustomApp;
using Model.DefaultApp;
using Model.SystemDefault;

namespace Model
{
    public class MyDbContext : DbContext
    {
        private string constr = string.Empty;

        public MyDbContext(string constr): base()
        {
            this.constr = constr;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseMySql(constr);//配置连接字符串
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            #region 系统默认
            var etCollectorConfigModel = modelBuilder.Entity<CollectInfoConfigModel>().ToTable("System_CollectInfoConfig");
            //TODO 其它配置
            etCollectorConfigModel.HasKey(p => p.ID).HasName("ID");



            var etCollectorUrlModel = modelBuilder.Entity<CollectorUrlModel>().ToTable("System_CollectorUrl");
            //TODO 其它配置
            etCollectorUrlModel.HasKey(p => p.ID).HasName("ID");



            var etPageInfoModel = modelBuilder.Entity<PageInfoModel>().ToTable("System_PageInfo");
            //TODO 其它配置
            etPageInfoModel.HasKey(p => p.ID).HasName("ID");


            var etProxyIPModel = modelBuilder.Entity<ProxyIPModel>().ToTable("System_ProxyIP");
            //TODO 其它配置
            etPageInfoModel.HasKey(p => p.ID).HasName("ID");


            var etCollecttorTaskModel = modelBuilder.Entity<CollecttorTaskModel>().ToTable("System_Collector_Task");
            //TODO 其它配置
            etPageInfoModel.HasKey(p => p.ID).HasName("ID");


            var etDefaultPageInfoModel = modelBuilder.Entity<DefaultPageInfoModel>().ToTable("default_pageinfo");
            //TODO 其它配置
            etPageInfoModel.HasKey(p => p.ID).HasName("ID");
            #endregion

            #region 用户app
            var etStdGovStdDetailModel = modelBuilder.Entity<StdGovStdDetailModel>().ToTable("custom_stdgovstdinfo");

            var etStandardcnDetailModel = modelBuilder.Entity<StandardcnDetailModel>().ToTable("custom_standardcninfo");
            #endregion
        }
    }
}
